package com.wzy.alllearning.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.wzy.alllearning.interceptor.RateLimitInterceptor;

@Configuration
public class WebConfig implements WebMvcConfigurer
{
	@Autowired
	private RateLimitInterceptor rateLimitInterceptor;

	@Override
	public void addInterceptors(InterceptorRegistry registry)
	{
		registry.addInterceptor(rateLimitInterceptor)
				.addPathPatterns("/api/**");
	}

	/**
	 * 姿态资源配置，不拦截
	 *
	 * @param registry
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry)
	{
		//	使用tomcat静态文件代理，配置本地文件目录的映射
		registry.addResourceHandler("/uploads/**")
				.addResourceLocations("file:");

		// swagger2做映射，达到放开权限的效果
		registry.addResourceHandler("/swagger-ui.html")
				.addResourceLocations("classpath:/META-INF/resource/");
		registry.addResourceHandler("/webjars/**")
				.addResourceLocations("classpath:/META-INF/resource/webjars/");

	}
}
